package com.imooc.exception;

import com.imooc.utils.IMOOCJSONResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

/**
 * 自定义异常处理类
 * @author gcq
 * @Create 2022-01-28
 */
@RestControllerAdvice
public class CustomExceptionHandler {

    /**
     * 文件上传大小不能超过500kb
     * @param exception 文件超出指定大小异常
     * @return 错误信息
     */
    @ExceptionHandler(value = MaxUploadSizeExceededException.class)
    public IMOOCJSONResult handlerMaxUploadFile(MaxUploadSizeExceededException exception) {
        return IMOOCJSONResult.errorMsg("图片上传不能超过500kb，请压缩或降低图片质量");
    }
}